home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #2 / Amiga Plus CD - 2004 - No. 02.iso / AmiSoft / Dev / misc / WHDLoad_dev.lha / WHDLoad / Src / slave-examples / kick13.asm < prev    next >
Encoding:
Assembly Source File  |  2004-01-18  |  7.4 KB  |  398 lines

  1. ;*---------------------------------------------------------------------------
  2. ;  :Modul.    kick13.asm
  3. ;  :Contents.    kickstart 1.3 booter example
  4. ;  :Author.    Wepl
  5. ;  :Original.
  6. ;  :Version.    $Id: kick13.asm 1.8 2004/01/18 13:29:40 wepl Exp wepl $
  7. ;  :History.    19.10.99 started
  8. ;        20.09.01 ready for JOTD ;)
  9. ;        23.07.02 RUN patch added
  10. ;        04.03.03 full caches
  11. ;        20.06.03 rework for whdload v16
  12. ;  :Requires.    -
  13. ;  :Copyright.    Public Domain
  14. ;  :Language.    68000 Assembler
  15. ;  :Translator.    Barfly V2.9
  16. ;  :To Do.
  17. ;---------------------------------------------------------------------------*
  18.  
  19.     INCDIR    Includes:
  20.     INCLUDE    whdload.i
  21.     INCLUDE    whdmacros.i
  22.     INCLUDE    lvo/dos.i
  23.  
  24.     IFD BARFLY
  25.     OUTPUT    "wart:.debug/Kick13.Slave"
  26.     BOPT    O+                ;enable optimizing
  27.     BOPT    OG+                ;enable optimizing
  28.     BOPT    ODd-                ;disable mul optimizing
  29.     BOPT    ODe-                ;disable mul optimizing
  30.     BOPT    w4-                ;disable 64k warnings
  31.     BOPT    wo-                ;disable optimize warnings
  32.     SUPER
  33.     ENDC
  34.  
  35. ;============================================================================
  36.  
  37. CHIPMEMSIZE    = $80000
  38. FASTMEMSIZE    = $80000
  39. NUMDRIVES    = 2
  40. WPDRIVES    = %1111
  41.  
  42. ;BLACKSCREEN
  43. ;BOOTBLOCK
  44. ;BOOTDOS
  45. ;BOOTEARLY
  46. ;CBDOSLOADSEG
  47. ;CBDOSREAD
  48. CACHE
  49. DEBUG
  50. ;DISKSONBOOT
  51. ;DOSASSIGN
  52. ;FONTHEIGHT    = 8
  53. HDINIT
  54. HRTMON
  55. IOCACHE        = 1024
  56. ;MEMFREE    = $100
  57. ;NEEDFPU
  58. ;POINTERTICKS    = 1
  59. SETPATCH
  60. ;STACKSIZE    = 6000
  61. ;TRDCHANGEDISK
  62.  
  63. ;============================================================================
  64.  
  65. slv_Version    = 16
  66. slv_Flags    = WHDLF_NoError|WHDLF_Examine
  67. slv_keyexit    = $59    ;F10
  68.  
  69. ;============================================================================
  70.  
  71.     INCLUDE    Sources:whdload/kick13.s
  72.  
  73. ;============================================================================
  74.  
  75.     IFD BARFLY
  76.     IFND    .passchk
  77.     DOSCMD    "WDate  >T:date"
  78. .passchk
  79.     ENDC
  80.     ENDC
  81.  
  82. slv_CurrentDir    dc.b    "wb13",0
  83. slv_name    dc.b    "Kickstarter for 34.005",0
  84. slv_copy    dc.b    "1987 Amiga Inc.",0
  85. slv_info    dc.b    "adapted for WHDLoad by Wepl",10
  86.         dc.b    "Version 0.7 "
  87.     IFD BARFLY
  88.         INCBIN    "T:date"
  89.     ENDC
  90.         dc.b    0
  91.     EVEN
  92.  
  93. ;============================================================================
  94. ; entry before any diskaccess is performed, no dos.library available
  95.  
  96.     IFD BOOTEARLY
  97.  
  98. _bootearly    blitz
  99.         rts
  100.  
  101.     ENDC
  102.  
  103. ;============================================================================
  104. ; bootblock from "Disk.1" has been loaded, no dos.library available
  105.  
  106.     IFD BOOTBLOCK
  107.  
  108. ; A1 = ioreq ($2c+a5)
  109. ; A4 = buffer (1024 bytes)
  110. ; A6 = execbase
  111.  
  112. _bootblock    blitz
  113.         jmp    (12,a4)
  114.  
  115.     ENDC
  116.  
  117. ;============================================================================
  118. ; like a program from "startup-sequence" executed, full dos process,
  119. ; HDINIT is required
  120.  
  121. ; the following example is extensive because it saves all registers and
  122. ;   restores them before executing the program, the reason for this that some
  123. ;   programs (e.g. MANX Aztec-C) require specific registers properly setup on
  124. ;   calling
  125. ; in most cases a simpler routine is sufficient :-)
  126.  
  127.     IFD BOOTDOS
  128.  
  129. _bootdos    lea    (_saveregs,pc),a0
  130.         movem.l    d1-d6/a2-a6,(a0)
  131.         move.l    (a7)+,(44,a0)
  132.  
  133.     ;open doslib
  134.         lea    (_dosname,pc),a1
  135.         move.l    (4),a6
  136.         jsr    (_LVOOldOpenLibrary,a6)
  137.         lea    (_dosbase,pc),a0
  138.         move.l    d0,(a0)
  139.         move.l    d0,a6            ;A6 = dosbase
  140.  
  141.     ;assigns
  142.         lea    (_disk1,pc),a0
  143.         sub.l    a1,a1
  144.         bsr    _dos_assign
  145.  
  146.     ;check version
  147.         lea    (_program,pc),a0
  148.         move.l    a0,d1
  149.         move.l    #MODE_OLDFILE,d2
  150.         jsr    (_LVOOpen,a6)
  151.         move.l    d0,d1
  152.         beq    .end
  153.         move.l    #300,d3
  154.         sub.l    d3,a7
  155.         move.l    a7,d2
  156.         jsr    (_LVORead,a6)
  157.         move.l    d3,d0
  158.         move.l    a7,a0
  159.         move.l    (_resload,pc),a2
  160.         jsr    (resload_CRC16,a2)
  161.         add.l    d3,a7
  162.         
  163.         cmp.w    #$dd8e,d0
  164.         beq    .versionok
  165.         pea    TDREASON_WRONGVER
  166.         jmp    (resload_Abort,a2)
  167. .versionok
  168.  
  169.     ;load exe
  170.         lea    (_program,pc),a0
  171.         move.l    a0,d1
  172.         jsr    (_LVOLoadSeg,a6)
  173.         move.l    d0,d7            ;D7 = segment
  174.         beq    .end
  175.  
  176.     ;patch
  177.         lea    (_pl_program,pc),a0
  178.         move.l    d7,a1
  179.         jsr    (resload_PatchSeg,a2)
  180.  
  181.     IFD DEBUG
  182.     ;set debug
  183.         clr.l    -(a7)
  184.         move.l    d7,-(a7)
  185.         pea    WHDLTAG_DBGSEG_SET
  186.         move.l    a7,a0
  187.         jsr    (resload_Control,a2)
  188.         add.w    #12,a7
  189.     ENDC
  190.  
  191.     ;call
  192.         move.l    d7,a1
  193.         add.l    a1,a1
  194.         add.l    a1,a1
  195.         moveq    #_args_end-_args,d0
  196.         lea    (_args,pc),a0
  197.         movem.l    (_saveregs,pc),d1-d6/a2-a6
  198.         jsr    (4,a1)
  199.  
  200.     IFD QUIT_AFTER_PROGRAM_EXIT
  201.         pea    TDREASON_OK
  202.         jmp    (resload_Abort,a2)
  203.     ELSE
  204.     ;remove exe
  205.         move.l    d7,d1
  206.         move.l    (_dosbase,pc),a6
  207.         jsr    (_LVOUnLoadSeg,a6)
  208.     ENDC
  209.  
  210. .end        moveq    #0,d0
  211.         move.l    (_saverts,pc),-(a7)
  212.         rts
  213.  
  214. _pl_program    PL_START
  215.         PL_END
  216.  
  217. _disk1        dc.b    "df0",0        ;for Assign
  218. _program    dc.b    "program to start",0
  219. _args        dc.b    10
  220. _args_end    dc.b    0
  221.     EVEN
  222.  
  223. _saveregs    ds.l    11
  224. _saverts    dc.l    0
  225. _dosbase    dc.l    0
  226.  
  227.     ENDC
  228.  
  229. ;============================================================================
  230. ; callback/hook which gets executed after each successful call to dos.LoadSeg
  231. ; can also be used instead of _bootdos, requires the presence of
  232. ; "startup-sequence"
  233.  
  234. ; the following example uses a parameter table to patch different executables
  235. ; after they get loaded
  236.  
  237.     IFD CBDOSLOADSEG
  238.  
  239. ; D0 = BSTR name of the loaded program as BCPL string
  240. ; D1 = BPTR segment list of the loaded program as BCPL pointer
  241.  
  242. _cb_dosLoadSeg    lsl.l    #2,d0        ;-> APTR
  243.         move.l    d0,a0
  244.         moveq    #0,d0
  245.         move.b    (a0)+,d0    ;D0 = name length
  246.     ;remove leading path
  247.         move.l    a0,a1
  248.         move.l    d0,d2
  249. .2        move.b    (a1)+,d3
  250.         subq.l    #1,d2
  251.         cmp.b    #":",d3
  252.         beq    .1
  253.         cmp.b    #"/",d3
  254.         beq    .1
  255.         tst.l    d2
  256.         bne    .2
  257.         bra    .3
  258. .1        move.l    a1,a0        ;A0 = name
  259.         move.l    d2,d0        ;D0 = name length
  260.         bra    .2
  261. .3    ;get hunk length sum
  262.         move.l    d1,a1        ;D1 = segment
  263.         moveq    #0,d2
  264. .add        add.l    a1,a1
  265.         add.l    a1,a1
  266.         add.l    (-4,a1),d2    ;D2 = hunks length
  267.         subq.l    #8,d2        ;hunk header
  268.         move.l    (a1),a1
  269.         move.l    a1,d7
  270.         bne    .add
  271.     ;search patch
  272.         lea    (.patch,pc),a1
  273. .next        move.l    (a1)+,d3
  274.         movem.w    (a1)+,d4-d5
  275.         beq    .end
  276.         cmp.l    d2,d3        ;length match?
  277.         bne    .next
  278.     ;compare name
  279.         lea    (.patch,pc,d4.w),a2
  280.         move.l    a0,a3
  281.         move.l    d0,d6
  282. .cmp        move.b    (a3)+,d7
  283.         cmp.b    #"a",d7
  284.         blo    .l
  285.         cmp.b    #"z",d7
  286.         bhi    .l
  287.         sub.b    #$20,d7
  288. .l        cmp.b    (a2)+,d7
  289.         bne    .next
  290.         subq.l    #1,d6
  291.         bne    .cmp
  292.         tst.b    (a2)
  293.         bne    .next
  294.     ;patch
  295.         lea    (.patch,pc,d5.w),a0
  296.         move.l    d1,a1
  297.         move.l    (_resload,pc),a2
  298.         jsr    (resload_PatchSeg,a2)
  299.     ;end
  300. .end
  301.     IFD DEBUG
  302.     ;set debug
  303.         clr.l    -(a7)
  304.         move.l    d1,-(a7)
  305.         pea    WHDLTAG_DBGSEG_SET
  306.         move.l    a7,a0
  307.         move.l    (_resload,pc),a2
  308.         jsr    (resload_Control,a2)
  309.         add.w    #12,a7
  310.     ENDC
  311.         rts
  312.  
  313. PATCH    MACRO
  314.         dc.l    \1        ;cumulated size of hunks (not filesize!)
  315.         dc.w    \2-.patch    ;name
  316.         dc.w    \3-.patch    ;patch list
  317.     ENDM
  318.  
  319. .patch        PATCH    2516,.n_run,_p_run2568
  320.         dc.l    0
  321.  
  322.     ;all upper case!
  323. .n_run        dc.b    "RUN",0
  324.     EVEN
  325.  
  326. _p_run2568    PL_START
  327.     ;    PL_P    0,.1
  328.         PL_END
  329.  
  330.     ENDC
  331.  
  332. ;============================================================================
  333. ; callback/hook which gets executed after each successful call to
  334. ; dos.LoadRead
  335.  
  336. ; the following example uses a parameter table to patch different files
  337. ; after they get loaded
  338.  
  339.     IFD CBDOSREAD
  340.  
  341. ; D0 = ULONG bytes read
  342. ; D1 = ULONG offset in file
  343. ; A0 = CPTR name of file
  344. ; A1 = APTR memory buffer
  345.  
  346. _cb_dosRead
  347.         move.l    a0,a2
  348. .1        tst.b    (a2)+
  349.         bne    .1
  350.         lea    (.name,pc),a3
  351.         move.l    a3,a4
  352. .2        tst.b    (a4)+
  353.         bne    .2
  354.         sub.l    a4,a2
  355.         add.l    a3,a2        ;first char to check
  356. .4        move.b    (a2)+,d2
  357.         cmp.b    #"A",d2
  358.         blo    .3
  359.         cmp.b    #"Z",d2
  360.         bhi    .3
  361.         add.b    #$20,d2
  362. .3        cmp.b    (a3)+,d2
  363.         bne    .no
  364.         tst.b    d2
  365.         bne    .4
  366.  
  367.     ;check position
  368.         move.l    d0,d2
  369.         add.l    d1,d2
  370.         lea    (.data,pc),a2
  371.         moveq    #0,d3
  372. .next        movem.w    (a2)+,d3-d4
  373.         tst.w    d3
  374.         beq    .no
  375.         cmp.l    d1,d3
  376.         blo    .next
  377.         cmp.l    d2,d3
  378.         bhs    .next
  379.         sub.l    d1,d3
  380.         move.b    d4,(a1,d3.l)
  381.         bra    .next
  382.  
  383. .no        rts
  384.  
  385. .name        dc.b    "tables01",0    ;lower case!
  386.     EVEN
  387.     ;offset, new data
  388. .data        dc.w    $4278,$c    ;original = 0b
  389.         dc.w    $45b4,$c    ;original = 0b
  390.         dc.w    0
  391.  
  392.     ENDC
  393.  
  394. ;============================================================================
  395.  
  396.     END
  397.  
  398.